package com.tanhua.server.controller;

import com.tanhua.common.utils.Cache;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {
    @Autowired
    private TodayBestService todayBestService;

    @GetMapping("todayBest")
    @Cache(time = "60") // 设置默认时间 60秒 默认的也是60秒。
    /**
     * 查询今日佳人的接口,从请求头中拿到token
     */
    public ResponseEntity<TodayBest> queryTodayBest(){
        // 调用查询佳人的实现方法
        TodayBest todayBest = null;
        try {
            todayBest = todayBestService.queryTodayBest();
            if (todayBest == null){
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
            }
        } catch (Exception e) {
            log.error("查询佳人失败 ~ userId = " + UserThreadLocal.get().getId(),e);
        }

        return ResponseEntity.ok().body(todayBest);
    }


    @GetMapping("recommendation")
    @Cache(time = "60") // 设置默认时间 60秒 默认的也是60秒。
    /**
     * 查询推荐好友列表的方法
     */
    public ResponseEntity<PageResult> recommendation(RecommendUserQueryParam queryParam){
        // 调用查询佳人列表的方法 查询的结果
        try {
            PageResult pageResult = todayBestService.queryRecommendation(queryParam);
            if (pageResult != null){
                return ResponseEntity.ok().body(pageResult);
            }
        } catch (Exception e) {
            log.error("查询佳人列表信息失败 ~ userId = " + UserThreadLocal.get().getId(), e );
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
